#include "ActionTurnAround.h"
#include "World.h"

ActionTurnAround::ActionTurnAround(float turnSpeed, float time)
{
	turnSpeed__ = turnSpeed;
	time__ = time;
	executer__ = 0 ; 
}

ActionTurnAround::~ActionTurnAround()
{
}

bool ActionTurnAround::execute(Entity* executer)
{
	executer__ = executer ;
	float elapsed = World::getWorld()->elapsedTime();
	time__ -= elapsed;
	if (time__ <= 0.0f)
		return true;
	else
		executer->getNode()->setRotation(vector3df(0.0f, executer->getNode()->getRotation().Y + (turnSpeed__ * elapsed), 0.0f));

	return false;
}

bool ActionTurnAround::checkConditions()
{
	if(executer__ != 0)
	{
		NPCEntity * realExecuter = dynamic_cast<NPCEntity *>(executer__) ;
		if(realExecuter->isUnderAttack())
		{
			return false ;
		}
	}
     return true ;    
}

